﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CRM.Database.Model.Customers>" %>

<%@ Import Namespace="System.Globalization" %>
<%@ Import Namespace="CRM.Database.Model" %>
<%@ Import Namespace="CRM.Resourses" %>
<%@ Import Namespace="DevExpress.Data" %>

<% Html.DevExpress().GridView(settings =>
                                    {
                                        settings.Name = "gdSalesTurnovers";
                                        settings.KeyFieldName = "IdTurnover";
                                        settings.CallbackRouteValues =
                                            new { Controller = "Customers", Action = "SalesTurnovers", customerId = Model.IdCustomer };
                                        settings.SettingsPager.PageSize = 20;
                                        settings.Settings.ShowFilterBar = GridViewStatusBarMode.Visible;
                                        settings.Settings.ShowFilterRow = true;
                                        settings.Settings.ShowGroupPanel = true;
                                        settings.Settings.ShowFooter = true;


                                        settings.TotalSummary.Add(SummaryItemType.Sum, "Amount").DisplayFormat = Resourses.Total + ": {0:c}";


                                        settings.GroupSummary.Add(SummaryItemType.Sum, "Amount").DisplayFormat = Resourses.Total + ": {0:c}";


                                        settings.CustomColumnDisplayText = (sender, e) =>
                                        {

                                            if (e.Column.FieldName == "Amount")
                                            {


                                                e.DisplayText = ((float)e.Value).ToString("c", CultureInfo.CreateSpecificCulture("fr-FR"));



                                            }
                                        };
                                        settings.SummaryDisplayText = (sender, e) =>
                                        {
                                            if (e.Item.FieldName == "Amount")
                                            {
                                                decimal value;
                                                decimal.TryParse(e.Value.ToString(), out value);
                                                e.Text = Resourses.Total + ": " + value.ToString("c", CultureInfo.CreateSpecificCulture("fr-FR"));
                                                // e.Text = value.ToString("euro", null);
                                            }
                                        };

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TurnoversAmount;
                                            column.FieldName = "Amount";

                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.Year;
                                            column.FieldName = "Year";

                                        });



                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.Month;
                                            column.FieldName = "Month";

                                        });

                                       
                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "LegalEntityName";
                                            column.Caption = Resourses.LegalEntities;
                                            
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "DealerName";
                                            column.Caption = Resourses.TurnoversDealers;
                                           
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdTurnoverClassification";
                                            column.Caption = Resourses.TurnoverClassifications;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;

                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {

                                                var col = new TurnoverClassificationsCollection();
                                                comboBoxProperties.DataSource = col.TurnoverClassificationsList;
                                                comboBoxProperties.TextField = "LocalizedName";
                                                comboBoxProperties.ValueField = "IdTurnoverClassification";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });
                                        //конец комбобокса
                                    })
       .Bind(Model.Sales).GetHtml();%>